home *** CD-ROM | disk | FTP | other *** search
/ Resource for Source: C/C++ / Resource for Source - C-C++.iso / misc_src / knowhow4 / bgipaint.h < prev    next >
C/C++ Source or Header  |  1995-11-01  |  7KB  |  225 lines

  1. #ifndef __BGI_PAINT_H_
  2. #define __BGI_PAINT_H_
  3.  
  4. /*  Adapted Paint class for usage with BGI, Win GDI or other library.
  5.     We suppose that this library is already initiated before functions call.
  6. */
  7.  
  8. /////////////////////////////////////////////////////////////////////////////
  9. /* List of graphics libraries. Could be continued. To use concrete library,
  10.    unremark concrete line. Or use Options - Compiler - Code generation -
  11.    Defines to define the necessary variable
  12. */
  13. //#define DOS_BGI
  14. //#define WIN_GDI
  15.  
  16. #include "simple.h"
  17. //////////////// Common color ref. and fill code ////////////////////////
  18. #ifndef RGB
  19.  
  20. #define COLORREF unsigned long
  21. #define BYTE uchar
  22. #define WORD unsigned short
  23. #define DWORD unsigned long
  24.  
  25. #define RGB(r,g,b) ((COLORREF)(((BYTE)(r)|((WORD)(g)<<8))| \
  26.     (((DWORD)(BYTE)(b))<<16)))
  27.  
  28. #endif RGB
  29. ////////////////////////////////////////////////////////////////////////////
  30. #ifdef DOS_BGI
  31.  
  32. #define PS_SOLID                SOLID_LINE
  33. #define PS_DASH                    DASHED_LINE
  34. #define PS_DOT                  DOTTED_LINE
  35. #define PS_DASHDOT              CENTER_LINE
  36. #define PS_DASHDOTDOT           CENTER_LINE
  37. #define PS_NULL                    SOLID_LINE
  38. #define PS_INSIDEFRAME          SOLID_LINE
  39.  
  40.  
  41. #define HS_BDIAGONAL            SLASH_FILL
  42. #define HS_CROSS            HATCH_FILL
  43. #define HS_DIAGCROSS            XHATCH_FILL
  44. #define HS_FDIAGONAL            BKSLASH_FILL
  45. #define HS_HORIZONTAL           LINE_FILL
  46. #define HS_VERTICAL            LTSLASH_FILL
  47.  
  48. #endif DOS_BGI
  49. ///////////////////////////
  50. #ifdef WIN_GDI
  51. #define SOLID_FILL              1
  52.  
  53. #define SOLID_LINE              PS_SOLID
  54. #define DASHED_LINE             PS_DASH
  55. #define DOTTED_LINE             PS_DOT
  56. #define CENTER_LINE             PS_DASHDOT
  57.  
  58.  
  59. #define SLASH_FILL              HS_BDIAGONAL
  60. #define HATCH_FILL              HS_CROSS
  61. #define XHATCH_FILL             HS_DIAGCROSS
  62. #define BKSLASH_FILL            HS_FDIAGONAL
  63. #define LINE_FILL               HS_HORIZONTAL
  64. #define LTSLASH_FILL            HS_VERTICAL
  65.  
  66. #endif WIN_GDI
  67. ////////////////////////////////////////////////////////////////////////////
  68. #define HS_SOLID                SOLID_FILL
  69. //////////////////////////////////////////////////////////
  70. #if !defined(__COLORS)
  71. #define __COLORS
  72.  
  73. enum COLORS { BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, LIGHTGRAY,
  74.     DARKGRAY, LIGHTBLUE, LIGHTGREEN, LIGHTCYAN, LIGHTRED, LIGHTMAGENTA,
  75.     YELLOW, WHITE };
  76. #endif __COLORS
  77. ////////////////////////////////////////////////////////////////////////////
  78. struct color_to_16
  79.     {
  80.     int color;
  81.     COLORREF colorref;
  82.     };
  83.  
  84. extern color_to_16 tricolors[16];
  85. ////////////////////////////////////////////////////////////////////////////
  86.  
  87. ///////////////////////////// Code for DOS BGI /////////////////////////////
  88. #ifdef DOS_BGI
  89. #include "paint.h"
  90. #include <graphics.h>
  91.  
  92.  
  93. struct To_Paint
  94.     {
  95.     To_Paint() { ::setcolor(BLACK); ::setfillstyle(SOLID_FILL, BLACK); }
  96.     int getx() { return ::getx(); }
  97.     int gety() { return ::gety(); }
  98.     int getcolor() { return ::getcolor(); }
  99.     int getcolor(COLORREF color);
  100.     COLORREF getcolorref() { return tricolors[::getcolor()].colorref; }
  101.  
  102.     void setcolor(int color) { ::setcolor(color); }
  103.     void setcolor(int r, int g, int b)
  104.     { setcolor(getcolor(RGB(r,g,b))); }
  105.  
  106.     void putpixel(int x, int y) { ::putpixel(x, y, getcolor()); }
  107.     void setlinestyle(int width, int style)
  108.     {  ::setlinestyle(style, 1, width); }
  109.     void setlinestyle(int style, unsigned int p, int width)
  110.     {  ::setlinestyle(style, p, width); }
  111.     void setfillstyle(int pattern, int col)
  112.     { ::setfillstyle(pattern, col); }
  113.     void setfillstyle(int style, COLORREF col)
  114.     {
  115.     setfillstyle(style, getcolor(col));
  116.     }
  117.  
  118.     void moveto(int x, int y) { ::moveto(x, y); }
  119.     void lineto(int x, int y) { ::lineto(x, y); }
  120.     void fillpoly(int numpoints, int* polypoints)
  121.     { ::fillpoly(numpoints, polypoints); }
  122.     void drawpoly(int numpoints, int far* points)
  123.     { ::drawpoly(numpoints, points); }
  124.     };
  125. #endif DOS_BGI
  126. //////////////////////////// End of DOS BGI part ////////////////////////////
  127. //////////////////////////// Code for Windows GDI ///////////////////////////
  128. #ifdef WIN_GDI
  129.  
  130. #define WIN31
  131.  
  132. #undef COLORREF 
  133. #undef BYTE 
  134. #undef WORD 
  135. #undef DWORD
  136.  
  137. #undef RGB
  138.  
  139. #include <owl.h>   // Or <windows.h>
  140. #include "paint.h"
  141.  
  142. struct To_Paint
  143.     {
  144.     int PenSize;
  145.     int PenStyle;
  146.     COLORREF color;
  147.  
  148.     int pattern_num;
  149.     COLORREF BrushColor;
  150.  
  151.     HDC DC;
  152.     /////////////////////////////////
  153.     To_Paint() { pattern_num = SOLID_FILL; PenSize = 1; PenStyle = PS_SOLID;
  154.          color = RGB(0,0,0); BrushColor = RGB(0,0,0); }
  155.     /////////////////////////////////
  156.     int getx() { POINT p; ::GetCurrentPositionEx(DC, &p); return p.x; }
  157.     int gety() { POINT p; ::GetCurrentPositionEx(DC, &p); return p.y; }
  158.     COLORREF getcolorref() { return color; }
  159.     int getcolor(COLORREF col);
  160.     int getcolor() { return getcolor(color); }
  161.  
  162.     void setcolor(int r, int g, int b)    { color = RGB(r,g,b); }
  163.     void setcolor(int c)
  164.     { color = tricolors[c].colorref; }
  165.  
  166.     void putpixel(int x, int y) { ::SetPixel(DC, x, y, getcolorref()); }
  167.     void setlinestyle(int width, int style)
  168.     { PenSize = width; PenStyle = style; }
  169.     void setlinestyle(int style, unsigned int, int width)
  170.     { PenSize = width; PenStyle = style; }
  171.  
  172.     void setfillstyle(int style, int col)
  173.     {
  174.     pattern_num = style;
  175.     BrushColor = tricolors[col].colorref;
  176.     }
  177.     void setfillstyle(int style, COLORREF col)
  178.     {
  179.     pattern_num = style;
  180.     BrushColor = col;
  181.     }
  182.  
  183.     void moveto(int x, int y) { ::MoveTo(DC, x, y); }
  184.     void lineto(int x, int y);
  185.     void fillpoly(int numpoints, int* polypoints);
  186.     void drawpoly(int numpoints, int far* points);
  187.     };
  188.  
  189. #endif WIN_GDI
  190. ///////////////////// End of Windows GDI part /////////////////////////
  191.  
  192. /////////////////////////////////////////////////////////////////////////////
  193. /*  KH_Paint class could draw graphics primitives using different libraries,
  194.     zoom, scroll, rotate (including complex rotations) and so on.
  195. */
  196.  
  197. class KH_Paint : public To_Paint, public Paint
  198.     {
  199.     public:
  200.     KH_Paint();
  201.  
  202.         int getx();
  203.         int gety();
  204.     loc get_CP();
  205.     void putpixel(int x, int y);
  206.     void line(int xstart, int ystart, int xend, int yend)
  207.         { moveto(xstart, ystart); lineto(xend, yend); }
  208.  
  209.     void lineto(int x, int y);
  210.     void moveto(int x, int y);
  211.     void circle(int x, int y, int radius)
  212.             { ellipse(x, y, 0, 360, radius, radius); }
  213.     void ellipse(int x, int y, int stangle, int endangle, int xr, int yr);
  214.     void rectangle(int left, int top, int right, int bottom);
  215.     void drawpoly(int numpoints, int far* points);
  216.     void fillpoly(int numpoints, int far* points)
  217.         { int f = fill; fill = ON; drawpoly(numpoints, points);
  218.         fill = f; }
  219.     void bar3d(int l, int t, int r, int b, int d, int top);
  220.     virtual void outtext(uchar far* str, int dir = 0);
  221.  
  222.     };
  223.  
  224. #endif __BGI_PAINT_H_
  225.